﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SLPropertyGrid
{
    public class PropertyPanel : PropertyGridBase
    {

        protected override void GenerateUI()
        {
            GenerateUIWithPanels();
        }

        private void GenerateUIWithPanels()
        {
            if (layoutRoot == null) return;
            StackPanel panel = new StackPanel();
            this.layoutRoot.Content = panel;
            foreach (var propertyCategory in Properties)
            {
                Border border = new Border();
                border.CornerRadius = new CornerRadius(15.0);
                border.Background = new SolidColorBrush(ContourColor);
                border.Margin = new Thickness(4.0);
                border.Padding = new Thickness(4.0);
                Expander exp = new Expander();
                border.Child = exp;
                exp.Header = propertyCategory.Name;
                exp.IsExpanded = true;
                panel.Children.Add(border);
                StackPanel panel2 = new StackPanel();
                exp.Content = panel2;
                GenerateProperties(propertyCategory.Properties, panel2);
            }
        }
        private void GenerateProperties(PropertyCollection propertyCollection, Panel panel)
        {
            foreach (var property in propertyCollection)
            {
                var c = GetControlForProperty(property);

                DataField field = new DataField();
                field.Content = c;
                field.Label = property.DisplayName;
                field.Description = property.Description;
                panel.Children.Add(field);
            }
        }

    }
}
